//
//  MeViewController.m
//  X-Tribe
//
//  Created by Miss.Ou on 16/3/29.
//  Copyright © 2016年 Miss.Ou. All rights reserved.
//

#import "MeViewController.h"
#import "MeTableViewCell.h"
#import "MeHeaderView.h"
#import "PersonalViewController.h"
#import "TOMyActivityViewController.h"

@interface MeViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)MeHeaderView *headerView;

@end

@implementation MeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createTableView];
}

#pragma mark - 创建TableView
-(void)createTableView
{

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[MeTableViewCell class] forCellReuseIdentifier:@"meTableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self createTableHeaderView];
    [self createTableFooterView];
    
}

#pragma mark - create TableHeaderView
-(void)createTableHeaderView{
    
    self.headerView = [[MeHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    self.tableView.tableHeaderView = self.headerView;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.headerView.userInteractionEnabled = YES;
    self.headerView.userName.userInteractionEnabled = YES;
    [self.headerView.userName addGestureRecognizer:tap];

    
}

#pragma mark - 轻拍方法
-(void)tapAction:(UITapGestureRecognizer *)tap{
    PersonalViewController *perVC = [[PersonalViewController alloc] init];
    perVC.title = @"我的资料";
    [self.navigationController pushViewController:perVC animated:YES];
}
#pragma mark - create TableFooterView
-(void)createTableFooterView{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, SCREEN_HEIGHT-49-50-64, SCREEN_WIDTH, 50);
    [button setTitle:@"退出登陆" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor colorWithRed:1.00 green:0.79 blue:0.57 alpha:1.00];
    [self.view addSubview:button];
}

#pragma mark - TableView代理方法

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"meTableViewCell" forIndexPath:indexPath];
    
    if (indexPath.section == 0){
        cell.label.text = @"活动管理";
    }
    else if (indexPath.section == 1){
        cell.label.text = @"我的活动";
    }
    else if (indexPath.section == 2){
        cell.label.text = @"个人中心";
    }
    else if (indexPath.section == 3){
        cell.label.text = @"我的档案";
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //选中时有置灰效果,离开时消失选中效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 1) {
        TOMyActivityViewController * myActVC = [[TOMyActivityViewController alloc] init];
        [self.navigationController pushViewController:myActVC animated:YES];
    }
    if(indexPath.section == 2){
        PersonalViewController *perVC = [[PersonalViewController alloc] init];
        perVC.title = @"个人中心";
        [self.navigationController pushViewController:perVC animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
